package hibernate;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import org.springframework.jdbc.core.RowMapper;

public class DefaultRowMapper implements RowMapper<Map<String,Object>>{
	
	private int start;
	private int limit;
	private int count = 0;
	
	public DefaultRowMapper(int start,int limit){
		this.start = start;
		this.limit = limit;
	}
	
	

	public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
	
		
		while(count ++ < start){rs.next();}
		
		
		
		Map<String, Object> itemMap = new HashMap<String, Object>();
		ResultSetMetaData meta = rs.getMetaData();
		for (int i = 1; i <= meta.getColumnCount(); ++i) {
			String name = meta.getColumnName(i);
			Object value = rs.getObject(i);
			itemMap.put(name, value);
		}
		
		return itemMap;
	}
	
	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

}
